package com.iot.service.mqtt.service.message;

import com.iot.service.mqtt.service.StoreStrategy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @Author: hszhou
 * @Date: 2025/4/18 15:51
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Service
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "mqtt", name = "store-strategy", havingValue = StoreStrategy.LOCAL)
@Slf4j
public class LocalMessageServiceImpl implements IMessage{

    private final static AtomicLong IDENTIFIER_MESSAGE = new AtomicLong(0);
    @Override
    public Long getMessageId() {
        return IDENTIFIER_MESSAGE.updateAndGet(current -> (current >= MAX_ID) ? 0 : current + 1);
    }
}
